package com.example.test1;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.example.test1.fragment.FaXianFragment;
import com.example.test1.fragment.HuDongFragment;
import com.example.test1.fragment.JieYueFragment;
import com.example.test1.fragment.QiangZuoFragment;
import com.example.test1.fragment.XinShengDaoHangFragment;

public class MainActivity extends FragmentActivity {
	private RadioGroup rg;
	private RadioButton rb1,rb2,rb3,rb4,rb5;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		rg=(RadioGroup)findViewById(R.id.rg);
		rb1=(RadioButton)findViewById(R.id.rb1);
		rb2=(RadioButton)findViewById(R.id.rb2);
		rb3=(RadioButton)findViewById(R.id.rb3);
		rb4=(RadioButton)findViewById(R.id.rb4);
		rb5=(RadioButton)findViewById(R.id.rb5);
		rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (rb1.getId() == checkedId) {
					changeFragment(new HuDongFragment());
				} else if (rb2.getId() == checkedId) {
					changeFragment(new JieYueFragment());
				} else if (rb3.getId() == checkedId) {
					changeFragment(new QiangZuoFragment());
				} else if (rb4.getId() == checkedId) {
					changeFragment(new XinShengDaoHangFragment());
				} else if (rb5.getId() == checkedId) {
					changeFragment(new FaXianFragment());
				}
			}
		});
		rb1.setChecked(true);
	}

	protected void changeFragment(Fragment targetFragment) {
		getSupportFragmentManager().beginTransaction()
		.replace(R.id.main_fragment, targetFragment, "fragment")
		.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
		.commit();
	}


}
